package com.rrqs.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import android.widget.CalendarView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.rrqs.utils.DateUtils;
import com.zadtek.xmqishi.R;


public class DatePickerActivity extends BaseActivity {

    ImageView mIvBack;
    CalendarView calendar_view;
    Button btn_confirm;

    private long mDate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_date_picker);
        mIvBack = (ImageView) findViewById(R.id.iv_back);
        calendar_view = (CalendarView) findViewById(R.id.calendar_view);
        btn_confirm = (Button) findViewById(R.id.btn_confirm);

        mDate = System.currentTimeMillis();
        mIvBack.setVisibility(View.VISIBLE);
        mIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        btn_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("date", mDate);
                setResult(RESULT_OK, intent);
                finish();
            }
        });
        calendar_view.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
            @Override
            public void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth) {
                mDate = DateUtils.convertStrToDate(year + ":" + (month + 1) + ":" + dayOfMonth, "yyyy:M:dd").getTime();
            }
        });

        calendar_view.setMaxDate(System.currentTimeMillis());
    }

}
